#!/usr/bin/env python
VERSION = 0.1

import sys
sys.path.append(".")
sys.path.append("lib")

from reportgen import ReportGenerator
from resources.ticket import Ticket
from marajo.appengine.api.users import User

from pprint import pprint

if __name__ == "__main__":
    from optparse import OptionParser
    parser = OptionParser(version = "%prog version " + str(VERSION))
    parser.add_option("-p", "--project", help="Limit to tickets in PROJECT")
    parser.add_option("-r", "--release", help="Limit to tickets in RELEASE")
    parser.add_option("-o", "--owner", help="Limit to tickets owned by OWNER")


    (options, args) = parser.parse_args()

    query = Ticket.find()
    if options.project:
        query.filter("project =", Project.get_by_ids(options.project))
    if options.release:
        query.filter("release =", Release.get_by_ids(options.release))
    if options.owner:
        query.filter("owner = ", User.get_by_ids(options.owner))

    gen = ReportGenerator(query)
    pprint(gen.project_work_report())
